<?php
// no direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');


class SimplelistingViewControlpanel extends JView {

	function display($tpl = null) {
	
		$model = &$this->getModel();
//
//		$latestEntries = $model->getLatestEntries();
//		$this->assignRef('latestEntries',$latestEntries);
//                $latestStats = $model->getLatestStats();
//		$this->assignRef('latestStats',$latestStats);
		$user = & JFactory::getUser();
		
                $document = & JFactory::getDocument();
                $db  =& JFactory::getDBO();
                $uri =& JFactory::getURI();
                $user =&JFactory::getUser();
                $document->setTitle( JText::_('TITLE_MAIN') );
                JToolBarHelper::title(JText::_('TITLE_MAIN'). ' [ ' . JText::_( 'TITLE_CPANEL' ) . ' ]' , 'simplelisting.png' );

                JToolBarHelper::preferences('com_simplelisting', '600', '600');

                require_once ( JPATH_COMPONENT . DS . 'models' . DS . 'controlpanel.php');
		$entriesModel = new SimplelistingModelControlpanel;
		$latestEntries = $entriesModel->latestEntries( 10);

		$this->assignRef( 'latestEntries', $latestEntries);
 
		
		parent::display($tpl);
	}

            function getTotals($TableName)
            {
            $db = & JFactory::getDBO();

            $query = 'SELECT COUNT(*) FROM #__simplelisting_'.$TableName;
            $db->setQuery($query);
            $result = $db->loadResult();
            return $result;
            }
            function getListings($TableName)
            {
            $db = & JFactory::getDBO();

            $query = 'SELECT COUNT(*) FROM #__'.$TableName;
            $db->setQuery($query);
            $result = $db->loadResult();
            return $result;
            }

}
